package cn.edu.scau.cmi.xiaozecheng.abstractFactory.factory;

import cn.edu.scau.cmi.xiaozecheng.abstractFactory.domainAbstractClass.Meat;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;


/**
 * @author xiao
 * @date 2019/10/12 2:50 PM
 */
public class Controller {
    public ComboBox<String> brand;
    @FXML
    private TextArea resultText;
    @FXML
    private Button button;
    @FXML
    private ComboBox<String> meatType;


    private AbstractFactory getFactory() {
        return AbstractFactory.getFactory(brand.getValue());
    }

    public Meat getMeat() {
        AbstractFactory abstractFactory = getFactory();
        String type = getMeatType();
        switch (type) {
            case "Chicken":
                return abstractFactory.createChicken();
            case "Beef":
                return abstractFactory.createBeef();
            case "Pork":
                return abstractFactory.createPork();
            default:
                throw new RuntimeException("没有该类");
        }
    }

    public void showResult() {
        resultText.appendText(getMeat().getName() + '\n');
    }

    private String getMeatType() {
        return meatType.getValue();
    }

}
